/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Deal.SalesView.TempData;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

/**
 *
 * @author 伯乐
 */
public class Coupon {
    private String type;
    private List<String> couponList = new ArrayList<>();
    private List<String> valueList = new ArrayList<>();
    private List<Integer> numList = new ArrayList<>();
    
    public Coupon(String t){
        type = t;
    }
    
    public String getType(){
        return type;
    }
    
    public void cleanCoupon(){
        couponList = new ArrayList<>();
        valueList = new ArrayList<>();
        numList = new ArrayList<>();
    }
    
    public List<String> getCouponList(){
        return couponList;
    }

    public List<Integer> getNumList() {
        return numList;
    }
    
    public Vector getCoupon(){
        Vector<Vector<String>> list = new Vector<>();
        for(int i=0; i<couponList.size(); i++){
            Vector<String> arr = new Vector<>();
            arr.add(couponList.get(i));
            arr.add(valueList.get(i));
            arr.add(String.valueOf(numList.get(i)));
            list.add(arr);
        }
        return list;
    }
    
    public int refreshData(String id, String value, int num){ //0：失败；1：添加成功；2：删除成功 3：修改成功
        if(num>=0){
            int loc;
            if((loc=couponList.indexOf(id))!=-1){
                if(num==0){
                    couponList.remove(loc);
                    valueList.remove(loc);
                    numList.remove(loc);
                    return 2;
                } else{
                    numList.set(loc, num);
                    return 3;
                }
            } else{
                couponList.add(id);
                valueList.add(value);
                numList.add(num);
                return 1;
            }
        }
        return 0;
    }
    
    public int getNum(String id){
        int loc;
        if((loc=couponList.indexOf(id))!=-1){
            return numList.get(loc);
        }
        return 0;
    }
    
    public String getValue(String id){
        int loc;
        if((loc=couponList.indexOf(id))!=-1){
            return valueList.get(loc);
        }
        return null;
    }
}
